package erQiao.yfl.app.service;

import erQiao.yfl.app.dao.entity.Prescription;
import erQiao.yfl.app.dao.mapper.PrescriptionMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 偏方
 */
@Service
public class PrescriptionService {
    private PrescriptionMapper prescriptionMapper;

    public int insertPrescription(Prescription prescription) {
        return prescriptionMapper.insert(prescription);
    }

    public int updateByPrimaryKey(Prescription prescription){
        return prescriptionMapper.updateByPrimaryKey(prescription);
    }

    public int delPrescriptionById(int id){
        return prescriptionMapper.deleteByPrimaryKey(id);
    }


    public Prescription selectByPrimaryKey(int id){
        return prescriptionMapper.selectByPrimaryKey(id);
    }

    /**
     * 用户偏方
     * @param id
     * @return
     */
    public List<Prescription> selectMyPrescriptionByUserId(int id){
        return prescriptionMapper.selectMyPrescriptionByUserId(id);
    }


    /**
     *  点赞
     * @param id
     * @return
     */
    public int updteUpvote(int id){
        Prescription prescription = prescriptionMapper.selectByPrimaryKey(id);
        Prescription _circle  =  new Prescription();
        _circle.setId(id);
        _circle.setUpvotenum(prescription.getUpvotenum()+1);
        return prescriptionMapper.updateByPrimaryKey(prescription);

    }

}
